<template>
	<view class="mainbgc">
		<header-top :messageInfo="{typeFlag:true,message:titletext,liner:false}"></header-top>
		<view class="mainpadding2">
			<view class="flexcenter" v-if="!list.data.length">
				<view class="placeholderimage"></view>
			</view>
			<view class="mainpadding_top ffffff radius itembox" v-for="item in list.data" :key="item.id"
				@click="jumpurl(item)">
				<view class="leftdetail">{{item.content}}</view>
				<view class="flexright rightdetail">
					<view class="smalltext">{{item.time_text}}</view>
					<view class="righticon2" v-if="type!=18 && type!=15 && type!=12 && type!=11 && type!=6 && type!=4"></view>
				</view>
			</view>
		</view>
		<u-modal :show="bfzshow" title="提示" content='系统检测到您当前存在拜访的客户,如需进入拜访任务需放弃当前拜访或完成拜访' cancelText='取消' confirmText='确定' :showCancelButton='true'
		 @confirm="confirm()" @cancel="bfzshow=false"></u-modal>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				titletext: "",
				type: 1, //类型
				page: 1,
				limit: 30,
				list: {
					data: []
				},
				bfzshow:false,
			}
		},
		onLoad(options) {
			//接收对象
			let data = JSON.parse(decodeURIComponent(options.msg));
			this.titletext = data.name
			this.type = data.type
		},
		onShow() {
			this.init()
		},
		methods: {
			init(isPage, page) {
				let _this = this;
				httpRequest.request('appapi/manage/message/detail', 'POST', {
					page: page || 1,
					limit: _this.limit,
					type: this.type,
				}, false, false, true).then(res => {
					console.log(res);
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							_this.list = resList
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			jumpurl(item) {
				// 18盘点完成,17库存预警,16客户流失预警,15推广日报，14转单/签收完成，13交账完成/撤销，12调度完成，11签到异常，10审核完成，9开单异常，8拜访任务
				// 7交账，6审批，5收款，4推单审核
				// 盘点完成----展示盘盈多少，盘亏多少不跳转，不要箭头18
				// 库存预警 ---- 库存预警详情
				// 客户流失预警----客户流失预警列表
				// 推广日报----不跳转，不要箭头15
				// 签收完成----司机送货“已签收”
				// 交账完成----收款对账,直接跳转
				// 调度完成----不跳转，不要箭头12
				// 签到异常----外勤轨迹对应员工列表，
				// 审核完成----销售单
				// 开单异常----销售单
				// 拜访任务----拜访任务
				// 交账----收款对账，直接跳转
				// 审批----对应单据类型跳转。
				// 收款----客户结算，单据编号跳详情
				// 推单审核
				console.log(item, "9999")
				let type = this.type
				if (type == 18) { //盘点完成
					return
				} else if (type == 17) { //库存预警
					uni.navigateTo({
						url: '/pages/homepage/news/kucunyj'
					})
				} else if (type == 16) { //客户流失预警
					uni.navigateTo({
						url: '/pages/homepage/news/kehuls'
					})
				} else if (type == 15) { //推广日报
					return
				} else if (type == 14) { //转单/签收完成
					// 跳转司机配送已签收
					uni.navigateTo({
						url: '/pages/workbench/xiaoshou/sijisongh?type=' + 2
					})
				} else if (type == 13 || type == 7) { //交账完成
					// 直接跳转收款对账
					uni.navigateTo({
						url: '/pages/workbench/caiwu/shouzhangdz'
					})
				} else if (type == 12) { //调度完成
					return
				}else if (type == 11) { //签到异常
					return
				}else if (type == 10 || type == 9) { //审核完成
					// 跳转销售单
					if(item.purchase_code){
						uni.navigateTo({
							url: '/pages/workbench/xiaoshou/xiaoshoudd?purchase_code=' + item.purchase_code
						})
					}
				}else if (type == 8) { //拜访任务
					httpRequest.request('appapi/manage/visit/visit_now', 'POST', {
					}, false, false, true).then(res => {
						if(res.data.visit_now){//正在拜访
							this.bfzshow = true
						}else{//没有进行中的拜访
							uni.navigateTo({
								url:'/pages/homepage/news/baifangdetail'
							})
						}
					}).catch(err => {
						httpRequest.toast(err.msg);
					})
				}else if (type == 6) { //审批跳转对应单据详情
					return
				}else if (type == 5) { //收款
					// 跳转客户结算
					if(item.purchase_code){
						uni.navigateTo({
							url: '/pages/workbench/caiwu/kehujsdetail?purchase_code=' + item.purchase_code
						})
					}
				}else if(type == 4){//推单审核
					return 
				}
			},
			confirm(){
				this.bfzshow = false
				httpRequest.request('appapi/manage/visit/visit_now', 'POST', {
				}, false, false, true).then(res => {
					if(res.data.visit_now){//正在拜访
						let obj = {
							customers_id:"",//客户id
							visit_id:res.data.visit_id,//拜访id
							visit_task_info_id:""//拜访任务id
						}
						uni.navigateTo({
							url:'/pages/workbench/xiaoshou/baifangmd?msg=' + encodeURIComponent(JSON.stringify(obj)),
							fail(err) {
								console.log(err,88888)
							},
						})
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
		}
	}
</script>

<style>
	.itembox {
		display: flex;
		align-items: flex-start;
		justify-content: space-between;
	}

	.smalltext {
		font-size: 28rpx;
		margin-right: 30rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
	}

	.leftdetail {
		flex: 7;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
		line-height: 33rpx;
	}

	.rightdetail {
		flex: 3;
	}
</style>
